package Hadoop;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;

public class Upload_and_download  {
    public void testCopyFromLocalFile() {
        // 创建作业，配置作业所需参数
        Configuration conf = new Configuration();
        conf.set("fs.defaultFS","hdfs://192.168.111.11:9000");
        FileSystem fs = null;
        try {
            fs = FileSystem.get(conf);
            //定义文件路径和上传路径
            Path src = new Path("E://hello.txt");
            Path dest = new Path("/test/hello.txt");
            //从本地上传到服务器上
            fs.copyFromLocalFile(src,dest);

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fs.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        System.out.println("上传成功");
    }

}
